﻿namespace the_moving_of_box
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //设置窗口大小/缓冲区大小
            int windowWidth = 100, windowHeight = 50;
            int bufferWidth = 100, bufferHeight = 50;

            Console.CursorVisible = false;
   

            //设置背景颜色等 好看点
            Console.BackgroundColor = ConsoleColor.Blue;
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Red;
            int x = 0;int y = 0;
            //switch语句移动方块
            while(true)
            {
                char direction = Console.ReadKey(true).KeyChar;
                //清空上一次界面，不然上次的画面仍会保留
                Console.Clear();

                //选择目前光标位置
                Console.SetCursorPosition(x, y);
                
                switch (direction)
                {
                    case 'd':
                        if(x<bufferWidth)
                        x += 2;
                        break;
                    case 'a':
                        if(x>=2)
                            x -= 2;
                        break;
                    case 'w':
                        if (y >= 2)
                            y -= 1;
                        break;
                    case 's':
                        if(y<bufferHeight)
                        y += 1;
                        break;
                    default:
                        Console.SetCursorPosition(20, 21);

                        Console.WriteLine("         please input a character like wasd");
                        break;


                }
                Console.SetCursorPosition(x, y);
                Console.Write("hello");
                Console.SetCursorPosition(40, 20);
                //显示目前坐标
                Console.Write("({0},{1})", x, y);





            }
        }
    }
}